<template>
	<view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isGZH:0
			}
		},
		onLoad(e) {
			
			if(e.isGZH==1){
				this.isGZH = 1
			}
			
			if(e.type){
				this.getCardList(e.type)
			}else{
				this.login()
			}
		},
		methods: {
			login(){
				let that=this
				
				uni.login({
					success(res2) {
						that.getOpenId(res2.code)
					}
				})
			},
			getOpenId(code){
				this.$http('/pay/api/wechart/getSessionNew',{
					code:code,
					appId:getApp().globalData.appId
				},res3=>{
					uni.setStorageSync('openId',res3.data.openid)
					uni.setStorageSync('sk',res3.data.sk )
					this.getLogin()
				},'GET')
			},
			getLogin(){
				this.$http('/minprogram/api/member/verify',{
					"wxOpenId":uni.getStorageSync('openId'),
					"pubopenid":""
				},res4=>{
						uni.setStorageSync('token',res4.data.token)
						if(this.isGZH){
							this.getCardList()
						}else{
							uni.reLaunch({
								url:'/pages/shopMall/shopMall'
							})
						}
				},'POST',()=>{
					uni.reLaunch({
						url:'/pages/register/register?isNiuniu=1&isGZH=' + this.isGZH
					})
				})
			},
			getCardList(type){
				this.$http('/minprogram/api/member/getOwnerMemberCardList',{
					condition:{
						dataTypeFlag:type?type:''
					}
				},res=>{
					if(res.data.items.length>0){
						let flag = true
						let info
						for(let i = 0;i<res.data.items.length;i++){
							if(res.data.items[i].isDefault){
								info = res.data.items[i]
								flag = false
								break;
							}
						}
						if(flag){
							info = res.data.items[0]
						}
						uni.setStorageSync('info',info)
						
						uni.reLaunch({
							url:'/pages/shopMall/shopMall'
						})
						
					}else{
						uni.reLaunch({
							url:'/pages/addCaiji/addCaijiXiaonei?isGZH=1'
						})
					}
				})
			},
		}
	}
</script>

<style>

</style>
